package com.deer.mvptest.service;

import android.content.Context;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 作者: 张金富 on 2017-09-06.
 * Email: zjf_deer@163.com
 * QQ: 1132740974
 * 描述:
 */

public class RetrofitHelper {
    private Context mContext;
    private static RetrofitHelper instance = null;
    private Retrofit mRetrofit = null;

    OkHttpClient client = new OkHttpClient();
    GsonConverterFactory factory = GsonConverterFactory.create();

    public static RetrofitHelper getInstance(Context mContext) {
        if (instance == null) {
            instance = new RetrofitHelper(mContext);
        }
        return instance;
    }

    private RetrofitHelper(Context mContext) {
        this.mContext = mContext;
        init();
    }

    private void init() {
        resetApp();
    }

    private void resetApp() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl("https://api.douban.com/v2/")
                .client(client)
                .addConverterFactory(factory)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
    }

    public RetrofitService getServer() {
        return mRetrofit.create(RetrofitService.class);
    }
}
